import React from 'react';
import cx from 'classnames';
import { routerRedux } from 'dva/router';
import { Flex, WingBlank, WhiteSpace, List, TextareaItem, Button, Result } from 'antd-mobile';
import { createForm } from 'rc-form';
import styles from './styles.less';

export default function InquiryList({ dispatch, list, filters, badge, myfilter, location }) {
  function routerHandler({ id, status, ...rest }) {
    const { pathname } = location;
    switch (status) {
      // 待处理
      case 0:
        return dispatch(routerRedux.push({
          pathname: `${pathname}/sheet`,
          state: {
            title: '填写问诊单',
            id: id,
            list: list,
          },
        }));
      // 已完成
      case 2:
        return dispatch(routerRedux.push({
          pathname: `${pathname}/${id}`,
          state: {
            title: '问诊单详情',
            id: id,
            ...rest,
          },
        }));
      default:
        // TODO...
    }
  };

  return (
     <WingBlank size="md">
      <WhiteSpace />
      {list.length ? (
        <div>
          {list.map(item =>
            <div key={item.id}>
            {(item.status == myfilter.status || myfilter.status == -1)?
              (<div><List>
                <List.Item
                  extra={<div>
                     {item.status==1?(<Button disabled size="small" style={{width: '1.5rem', float: 'right', color: '#fff',background: 'orange'}}>已填写</Button>:""):""}
                     {item.status==0?(<Button disabled size="small" style={{width: '1.5rem', float: 'right', color: '#fff',background: '#727171'}}>待填写</Button>:""):""}
                     {item.status==2?(<Button disabled size="small" style={{width: '1.5rem', float: 'right', color: '#fff',background: '#9ACD32'}}>已完成</Button>:""):""}
                  </div>}
                  onClick={() => routerHandler(item)}>
                  {item.name}发来的问诊单
                  <List.Item.Brief>
                    {item.updateTime}
                  </List.Item.Brief>
                </List.Item>
                </List> 
                <WhiteSpace /></div>)
                :false
            }
            </div>
          )}
        </div>
      ): (
        <Result message="暂无记录" />
      )}

    </WingBlank>
  );
}